<!--
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-09-22 10:26:19
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-09-24 13:06:25
 * @Description: 
 * 
-->
<template>
  <el-dialog draggable overflow v-model="visible" :title="titleMap[mode]" :width="500" destroy-on-close
    @closed="$emit('closed')">
    <el-tabs type="border-card">
      <el-tab-pane ref="tab" label="基础信息">
        <el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px">
          <el-row :gutter="40" justify="space-evenly">
            <el-col :span="12">
              <el-form-item label="名称" prop="name">
                <el-input v-model="form.name"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="排序" prop="sort">
                <el-input v-model="form.sort" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="默认客户科目" prop="customer_subject_id">
                <sk-select-group v-model="form.customer_subject_id" :list="subjectList" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="默认供应商科目" prop="supplier_subject_id">
                <sk-select-group v-model="form.supplier_subject_id" :list="subjectList" />
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" :autosize="{ minRows: 4, maxRows: 4 }" type="textarea" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import skSelectGroup from "@/components/skSelectGroup";
export default {
  emits: ["success", "closed"],
  components: { skSelectGroup },
  data() {
    return {
      mode: "add",
      titleMap: {
        add: "新增",
        edit: "编辑",
      },
      subjectList: [],
      form: {},
      rules: {
        name: { required: true, message: "类别名称必填" },
      },
      visible: false,
      isSaveing: false,
    };
  },

  mounted() {
    this.getSubject();
  },
  methods: {

    //显示
    open(mode = "add") {
      this.mode = mode;

      this.visible = true;

      return this;
    },
    //表单提交方法
    submit() {

      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          var res = await this.$API.finance.amountoddType.save.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          }
        }
      });
    },
    getSubject() {
      this.$API.basedata.subject.menulist.get().then((res) => {
        this.subjectList = res.data;
      });
    },
    //表单注入数据
    setData(data) {
      Object.assign(this.form, data);
    },
  },
};
</script>
<style></style>
